//-----------------Sonic CD Door Script-------------------//
// Yeah...

// Aliases
#alias Object.Value0	:	Object.Timer
#alias Object.Value1	:	Object.YVelocity
#alias Object.Value2	:	Object.T4
#alias Object.Value3	:	Object.TimerExtra
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod


#alias Object.PropertyValue		:	PushButton.Pressed	

 
// Priority
#alias 1 : PRIORITY_ACTIVE

// Priority
#alias 0	:	PRIORITY_BOUNDS
#alias 1	:	PRIORITY_ACTIVE

// States
#alias 0	:	DOOR_STAND
#alias 1	:	DOOR_UP
#alias 2	:	DOOR_UP_STAND
#alias 3	:	DOOR_DOWN

sub ObjectMain
	Object.DrawOrder = 1
	if Object.State == DOOR_UP
		Object.Timer++
		if Object.Timer == 2
			Object.TimerExtra++
			Object.Timer = 0
			if Object.PropertyValue == 0
				Object.YVelocity = -50000
			else
				Object.YVelocity = 50000
			end if
			Object.YPos += Object.YVelocity
		end if
		if Object.TimerExtra == 167
			Object.TimerExtra = 0
			Object.YVelocity = 0
			Object.Timer = 0
			Object.State = DOOR_UP_STAND
		end if
	end if
	
	if PushButton[-2].Pressed == true
		if	Object.State == DOOR_STAND
			Object.State    = DOOR_UP
			PlayStageSFX(8, false)
		end if
		//Object.T4 = 1
	end if
end sub

sub ObjectPlayerInteraction
	PlayerObjectCollision(C_BOX, -64, -32, 64, 128)
	PlayerObjectCollision(C_BOX, -64, -128, 64, -96)
end sub

sub ObjectDraw
	DrawSprite(0)
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects4.gif")

	TempValue0 = HUD.CurrentTimePeriod
	TempValue1 = 0
	TempValue0 *= 128
	TempValue1 += TempValue0 
	SpriteFrame(-64, -128, 128, 256, TempValue1, 0)	// #0
	
	
	// Set this object to always active
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[MovingGround]
			Object[ArrayPos0].Priority = PRIORITY_ACTIVE
		end if
		ArrayPos0++
	loop
	
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("R2/Objects4.gif")
	SpriteFrame(-64, -128, 128, 256, 0, 0)	// #0

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub